﻿using LiteBlog.Common.Entities;
using LiteBlog.Components;
using LiteBlog.Components.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LiteBlog.Controllers.Filters
{
    public class TagNotFoundFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string id = (string)filterContext.ActionParameters["id"];
            var controller = filterContext.Controller as TagController;
            var tag = controller.TagComponent.Get(id);
            if (tag == null)
            {
                filterContext.Result = controller.GetViewResult("PageNotFound", null);
                return;
            }
            filterContext.RouteData.Values["tagName"] = tag.Name;
        }
    }
}